
/**
 * @copyright SilverBiology, LLC
 * @author SilverBiology, LLC
 * @website http://www.silverbiology.com
*/
Ext.ns('TaxaonTagger');

TaxaonTagger.clbusage = function(config){
	
	
	this.store = new Ext.data.JsonStore({
				proxy: new Ext.data.ScriptTagProxy({
					url: 'http://ecat-dev.gbif.org/ws/usage/'
				})
			,	fields: [
						'taxonID'
					, 	'datasetID'
					, 	'higherTaxonID'
					,	'nameID'
					,	"scientificName"
					,	"rank"
					,	"isSynonym"
					,	"taxonomicStatus"
					,	"numChildren"
					,	"numDescendants"
					,	"rating"
					,	"datasetName"
					,	"datasetType"
					]
			,	root: 'data'
			,	baseParams:{
					"rkey":1
				,	"q":"Blechnum"
				,	"sort":"alpha"
				,	"pagesize":10
				}
			//,	autoLoad: true
		})
		
		
	Ext.apply(this, config, { 
				title:'GBIF Checklist Bank'
			,	width:'100%'
			,	height:500
			,	border:true
			,	tpl:new Ext.XTemplate(
						'<tpl for=".">',
							'<div>',
							'{scientificName}<br/>{accordingTo}<br/>{canonicalName}</div>',
						'</tpl>'
					)
			,	tbar:['Taxon: ',{
						xtype: 'combo'	
					,	store: this.store
					,	mode: 'local'
					,	displayField: 'scientificName'
					,	valueField: 'taxonID'
					,	typeAhead: false
					,	triggerAction: 'all'
					,	editable: false
					,	width: 250
					,	listeners: {
							select: function(f,r,i){
								this.renderData(r.data.taxonID);
							}
						,	scope:this	
						}		
				}]
		});
		
		TaxaonTagger.clbusage.superclass.constructor.call(this,config);
};
Ext.extend(TaxaonTagger.clbusage , Ext.Panel, {
		renderData:function(val){
			Ext.ux.JSONP.request('http://ecat-dev.gbif.org/ws/usage/'+val,{ //6498097', {
					callbackKey: 'callback'
				,	scope:this	
				,	callback: function(response){
						if(response.success)
							this.update(response.data);
						else{
						}	
					}
				});
        }
	,	loadName:function(name){
			this.store.baseParams.q = name;
			this.store.load();
		}		
});	
	